package com.iceGame;

import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.physics.box2d.CircleShape;
import com.badlogic.gdx.physics.box2d.Filter;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.MassData;
import com.badlogic.gdx.physics.box2d.PolygonShape;
import com.badlogic.gdx.physics.box2d.World;
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;

public class Fireball extends MovingGameObject{

	public float stateTime = 0f;
	public int state = NORMAL;
	public static int EXPLODING = 1;
	public static int NORMAL = 0;
	public static int DESTROIED = 2;
	public static float EXPLODING_TIME = 0.4f;
	public Fireball(PhysicsWorld world) {
		super(world);
		
	}
	public Fireball(PhysicsWorld world,float x, float y, float width, float height){
		//position = new Vector2(x,y);
		super(world,x,y,width,height);
		//setBody(world.world,x,y,width,height);

	}
	protected void setBody(World world, float x, float y, float width,float height) {		
		//create the shape			
		  CircleShape circle = new CircleShape();
          circle.setRadius(width/2);
		
		//create  FixtureDef	
		FixtureDef ShapeDef = new FixtureDef();
		ShapeDef.shape = circle;
		ShapeDef.filter.categoryBits=PhysicsWorld.CATEGORY_FIREBALL;
		ShapeDef.filter.maskBits=PhysicsWorld.MASK_FIREBALL;	
		
		//create  BodyDef
		BodyDef bodydef = new BodyDef();
		bodydef.position.set(x,y);
		bodydef.type = BodyType.KinematicBody;
		
		// create Body
		body = world.createBody(bodydef);		
		body.createFixture(ShapeDef);
		
		MassData data = new MassData();
		data.mass = 0;
		data.I = 0;
		body.setMassData(data);		
	}
	@Override
	public void update(float deltaTime){
		super.update(deltaTime);
		if (state == DESTROIED){
			
		}
		else{
			stateTime += deltaTime;
			if (state == EXPLODING && stateTime >= EXPLODING_TIME){
				state = DESTROIED;
				body.destroyFixture(body.getFixtureList().get(0));
			}
		}
	}
	
    public void explode() {
        state = EXPLODING;
        stateTime = 0f;
    }

}
